<?php

// ------------------------------------------------------------------------
// |@Author       : Jarmin <topextend@qq.com>
// |@----------------------------------------------------------------------
// |@Date         : 2025-05-04 23:29:01
// |@----------------------------------------------------------------------
// |@LastEditTime : 2025-05-09 20:48:09
// |@----------------------------------------------------------------------
// |@LastEditors  : Jarmin <topextend@qq.com>
// |@----------------------------------------------------------------------
// |@Description  :
// |@----------------------------------------------------------------------
// |@FilePath     : Model.php
// |@----------------------------------------------------------------------
// |@Copyright (c) 2025 http://www.ladmin.cn All Rights Reserved.
// ------------------------------------------------------------------------
declare (strict_types=1);

namespace think\admin;

abstract class Model extends \think\Model
{
    /**
     * 创建时间字段
     * @var string
     */
    protected $createTime = 'created_at';

    /**
     * 更新时间字段
     * @var string
     */
    protected $updateTime = 'updated_at';

    /**
     * 软删除字段
     * @var string
     */
    protected $deleteTime = 'deleted_at';

    /**
     * 获取分页数据
     * @param array $where
     * @param string $order
     * @param int $page
     * @param int $limit
     * @return array
     */
    public function getList(array $where = [], string $order = 'id desc', int $page = 1, int $limit = 15): array
    {
        $query = $this->where($where)->order($order);
        $total = $query->count();
        $items = $query->page($page, $limit)->select();

        return [
            'items' => $items,
            'total' => $total,
            'page' => $page,
            'limit' => $limit
        ];
    }

    /**
     * 获取单条数据
     * @param int $id
     * @return Model|null
     */
    public function getDetail(int $id): ?Model
    {
        return $this->find($id);
    }
}
